package com.example.springbook.controller;

import com.example.springbook.bean.Admin;
import com.example.springbook.service.AdminService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping(value = "/admin")
public class AdminController {
    @Autowired
    private AdminService adminService;

    @RequestMapping(value = "/admin", method = RequestMethod.POST)
    public boolean addAdmin(@RequestBody Admin admin) {
        System.out.println("新增数据：");
        return adminService.addAdmin(admin);
    }

    @RequestMapping(value = "/admin", method = RequestMethod.PUT)
    public boolean updateAdmin(@RequestBody Admin admin) {
        System.out.println("更新数据：");
        return adminService.updateAdmin(admin);
    }

    @RequestMapping(value = "/admin", method = RequestMethod.DELETE)
    public  boolean delete(@RequestParam(value = "id", required = true)int Id) {
        System.out.println("删除数据：");
        return adminService.deleteAdmin(Id);
    }

    @RequestMapping(value = "/login",method = RequestMethod.GET)
    public String selectAdmin(@RequestParam(value = "id",required = true) int id){
        System.out.println("selectAdmin");
        return adminService.selectAdmin(id);
    }

    @RequestMapping(value = "/findAdminName",method = RequestMethod.GET)
    public String findAdminName(@RequestParam(value = "id",required = true) int id){
        System.out.println("findAdminName");
        return adminService.findAdminName(id);
    }


    @RequestMapping(value = "/adminAll", method = RequestMethod.GET)
    public List<Admin> findByAdminAge() {
        System.out.println("查询所有数据：");
        return adminService.findAll();
    }
}
